import unittest
import requests


class WeiDu(unittest.TestCase):
    def setUp(self) -> None:
        print('开始')

    def tearDown(self) -> None:
        print('结束')

    host = 'http://10.59.9.18/'
    # 登录
    token = None
    userId = None
    nickName = None

    def test_01(self):
        url = WeiDu.host + 'car-user/user/v1/login'
        json = {'userName': 'zhangsan', 'passwd': '123456'}
        login = requests.post(url=url, json=json)
        print(login.json())
        WeiDu.userId = login.json()['result']['userId']
        WeiDu.token = login.json()['result']['token']
        print(WeiDu.userId)
        print(WeiDu.token)
        # 断言zhangsan 提取nickName
        WeiDu.nickName = login.json()['result']['nickName']
        self.assertEqual('zhangsan', WeiDu.nickName)

# 查询品牌列表
    brandId = None

    def test_02(self):
        url = WeiDu.host + 'car-choose/car/v1/findBrandList'
        BrandList = requests.get(url=url)
        print(BrandList.json())
        # 提取id
        WeiDu.brandId = BrandList.json()['result'][0]['brandList'][0]['brandId']
        print('brandId:', WeiDu.brandId)

    # 根据汽车品牌id查询汽车系列
    categoryId = None
    carLabels = None

    def test_03(self):
        url = WeiDu.host + 'car-choose/car/v1/findCarModelList'
        data = {'brandId': str(WeiDu.brandId), 'page': '1', 'size': '1'}
        BrandList = requests.get(url=url, params=data)
        print(BrandList.json())
        # 提取id
        WeiDu.categoryId = BrandList.json()['result'][0]['categoryId']
        print('categoryId:', WeiDu.categoryId)
        # 断言['空间充足', '内饰整洁']
        WeiDu.carLabels = BrandList.json()['result'][0]['carLabels']
        print('carLabels:', WeiDu.carLabels)
        self.assertNotEqual('["空间充足", "内饰整洁"]', WeiDu.carLabels)

    # 加入专区
    def test_04(self):
        url = WeiDu.host + 'car-circle/circle/verify/v1/joinCircleColumn'
        header = {'userId': str(WeiDu.userId), 'token': WeiDu.token}
        data = {'brandId': str(WeiDu.brandId), 'categoryId': WeiDu.categoryId}
        CircleColumn = requests.post(url=url,headers=header ,json=data)
        print(CircleColumn.json())

    # 查询我加入的车友圈专区
    columnId=None
    def test_05(self):
        url = WeiDu.host + 'car-circle/circle/verify/v1/findMyColumnList'
        header = {'userId': str(WeiDu.userId), 'token': WeiDu.token}
        ColumnList = requests.get(url=url,headers=header)
        print(ColumnList.json())
        # 提取 columnId
        WeiDu.columnId=ColumnList.json()['result'][0]['columnId']
        print(WeiDu.columnId)

    # 退出专区
    def test_06(self):
        url = WeiDu.host + 'car-circle/circle/verify/v1/quitCircleColumn'
        header = {'userId': str(WeiDu.userId), 'token': WeiDu.token}
        data = {'columnId': WeiDu.columnId}
        ColumnList = requests.delete(url=url, headers=header,data=data)
        print(ColumnList.json())

if __name__ == '__main__':
    unittest.main()
